﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PMS.BusinessFacade;
using PMS.EntityManage;
using PMS.Common;
using PMS.EntityQuery;
using System.Data.SqlClient;
using System.Collections.Generic;
using EntityManage;
using BusinessFacade;
using System.IO;

public partial class Modules_Default_MyRecvMessageReply : System.Web.UI.Page
{
    IOther_MessageHandler msgHandler = new Other_MessageManage();
    IOther_MessageReceverHandler msgRecvHandler = new Other_MessageReceverManage();
    ISys_UserHandler userHandler = new Sys_UserManage();
    ISys_OrganizationHandler orgHandler = new Sys_OrganizationManage();
    ISys_OrganizationHandlerExt orgExtHandler = new Sys_OrganizationManageExt();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!CheckPurviews())
        {
            Response.Redirect("~/Login.aspx");
        }
        if (!IsPostBack)
        {
            int msgId = int.Parse(Request["ID"]);
            Other_MessageQuery msgQuery = msgHandler.GetOther_MessageQuery(msgId);
            txtTitle.Text = "Re:" + msgQuery.Title;
        }
    }

    private bool CheckPurviews()
    {
        if (Session["UserPurviews"] != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        int userId = int.Parse(Session["CurrentUserID"].ToString());
        int oriMsgId = int.Parse(Request["ID"]);

        Other_MessageQuery msgQuery = new Other_MessageQuery();
        msgQuery.Title = txtTitle.Text;
        msgQuery.User_ID = userId;
        msgQuery.Content = txtContent.Text;
        msgQuery.Create_Time = DateTime.Now;

        int msgId = 0;
        msgHandler.InsertOther_Message(msgQuery, ref msgId);

        if (msgId != 0)
        {
            msgQuery = msgHandler.GetOther_MessageQuery(oriMsgId);
            Other_MessageReceverQuery recvQuery = new Other_MessageReceverQuery();
            recvQuery.Message_ID = msgId;
            recvQuery.User_ID = msgQuery.User_ID;
            recvQuery.Status = 0;

            msgRecvHandler.InsertOther_MessageRecever(recvQuery);
        }

        Jscript.Alert("回复成功");
        Jscript.ReturnAndClose(this.Page, "true");
    }

}
